home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1999-03-04 | 9.1 KB | 332 lines | [ TEXT/ToyS]
(* V1.13 ◊ This script is PD 1998 by AKUA interactive media AG. Drop a remote application onto PowerDown to configure it. Drop the Finder from a remote machine onto PowerDown to have the choice of Restart, Shutdown or Quit or drop any application to have it quit when this script is subsequently run. Drop a folder or volume to have this script unmount it when run V1.13 - 981019 - Change operation to open items if they are dropped on us V1.12 - 981005 - V1.26 of Akua Sweets / MacOS 8.5 V1.10 - Fix gasLinkNeed variable syntax V1.09 - Let user choose item if run unactivated. Support new KeyChain format. V1.08 - Remove all Server support. Only linking to slim it down. V1.07 - Add gossip functionality *) -- User setable properties property kasAllowAlerts : true -- Set to false to stop any alerts from appearing property kasServerAlerts : true -- Set to false to stop warnings about missed servers property kasFinder : "Finder" -- name of application that can shutdown and restart -- Internal/User setable globals property gasLinkNeed : true property kasLinkUserDft : "CasaVision" -- Our friend on all machines property kasLinkPassDft : "" -- Our friend's password on all machines global gasLinkSet -- Has the friend been looked up? global gasLinkUser -- Used to connect (KeyChain Lookup) global gasLinkPass -- Internal globals property gasOurZone : "" -- Set to zone of gasOurAlias property gasOurServer : "" -- Set to server of gasOurAlias property gasOurName : "" -- Name of application on remote server property gasOurAction : "" -- Set to choice of user (quit, shutdown, restart) on run set gasLinkSet to false if (gasOurAction is "") then ShowInitAlert() else if (gasOurName is not "") then RemoteAction(gasOurName, gasOurServer, gasOurZone, gasOurAction, {}) else PutAwayVol(gasOurVol) end if end run on open fsObjs set gasLinkSet to false if (gasOurName is "") or (option key down of (input state)) then if the number of items in fsObjs is not 1 then ShowInitAlert() else if (gasOurName is "") or ShowChoice("You have the option key pressed." & return & return & ¬ "Do you wish to reinitialize this script with the object you dropped on it?") then SetScriptAlias(item 1 of fsObjs) end if else RemoteAction(gasOurName, gasOurServer, gasOurZone, gasOurAction, fsObjs) end if end open on RemoteAction(appName, serverName, zoneName, whatToDo, objsToOpen) -- Get the user/password GetFriend(false) if (serverName is not "") then ¬ talk as user gasLinkUser ¬ with password gasLinkPass ¬ on server serverName ¬ in AppleTalk zone zoneName if serverName is "" then set suspect to application appName else set suspect to application appName ¬ of machine serverName ¬ of zone zoneName end if try -- Don't wait for a response, assume the aliases are correct? if (objsToOpen is not {}) then repeat with fsObj in objsToOpen tell suspect to open (fsObj as alias) end repeat else if (whatToDo is "Shutdown") then tell suspect to «event fndrshut» else if (whatToDo is "Restart") then tell suspect to «event fndrrest» else if (whatToDo is "Quit") then tell suspect to quit else beep 2 end if on error err ShowConnectAlert(appName, err) end try end RemoteAction on ChooseScriptAlias() if ShowChoices("Do you wish to activate this script with a folder/volume or a file?", {"Folder", "File"}) is "File" then set myObj to ¬ choose file with prompt "Choose a server file for this PowerScript RA" else set myObj to ¬ choose folder with prompt "Choose a server folder or volume for this PowerScript RA" end if SetScriptAlias(myObj) end ChooseScriptAlias on SetScriptAlias(aliasObj) -- My Path set myPath to (path to me) -- Grab an alias set aInfo to alias info from aliasObj set fInfo to basic info for aliasObj -- Save the info we need set gasOurServer to alias server of aInfo set gasOurZone to alias zone of aInfo set gasOurVol to alias volume of aInfo set gasOurName to original name of aInfo -- Set our name to dropped name set gasLinkNeed to true set newName to (catalog name of fInfo) if (catalog kind of fInfo) is a folder then set gasOurAction to "Put Away" set gasLinkNeed to false set newName to gasOurVol else if (gasOurName is kasFinder) then set choice to display dialog "What do you wish to have the " & kasFinder & ¬ " on " & gasOurServer & ¬ " do when this script is run?" buttons ¬ {"Quit", "Restart", "Shutdown"} default button 3 set gasOurAction to button returned of choice if (gasOurAction is not "Quit") then set newName to gasOurServer else set gasOurAction to "Quit" end if -- Get the user/password GetFriend(false) -- Set our icon to dropped icon set ourIcon to (the icon for aliasObj) set the icon of myPath to ourIcon with compatibility -- Refresh our new status in the finder try tell application "Finder" to update myPath -- only works with OS 8 on error beep end try -- Set our new name set newName to "≈ " & gasOurAction & " " & newName if (length of newName > 31) then set newName to the text from character 1 to 31 of newName try collate myPath renaming it to newName on error beep end try end SetScriptAlias on GetFriend(override) -- Should later use some modifier key to override?!? if (gasOurServer is "") then -- Local? set gasLinkSet to true set gasLinkUser to kasLinkUserDft set gasLinkPass to kasLinkPassDft else if (gasLinkNeed) then GetOneFriend(override) end if end GetFriend on GetOneFriend(override) set isLink to true -- Only linking in this script! set userMode to "linking" set passButtons to {"Cancel", "OK"} set passButton to 2 if (gasLinkSet) then set defUser to gasLinkUser set defPass to gasLinkPass else set defUser to kasLinkUserDft set defPass to kasLinkPassDft end if set usrPwd to KeyChainLookUp(gasOurZone, gasOurServer, isLink) if (override or usrPwd is {}) then set chosen to display dialog ¬ "Enter the friendly " & userMode & ¬ " user's name…" default answer defUser ¬ default button 2 with icon note if (the button returned of chosen is "OK") then set defUser to the text returned of chosen else return end if set chosen to display dialog ¬ "Enter the friendly " & userMode & ¬ " user's password…" buttons passButtons ¬ default answer defPass default button passButton with icon note if (the button returned of chosen is not "Cancel") then set defPass to the text returned of chosen else return end if -- Save encrypted user/pass for future access KeyChainSave(gasOurZone, gasOurServer, isLink, defUser, defPass, "") else set defUser to item 1 of usrPwd set defPass to item 2 of usrPwd end if set gasLinkSet to true set gasLinkUser to defUser set gasLinkPass to defPass end GetOneFriend on PutAwayVol(volName) -- Volume try tell application "Finder" update item named volName pause for 2 with seconds timing -- Give some time to the Finder? put away item named volName end tell on error beep end try end PutAwayVol on ShowConnectAlert(appName, err) if (kasServerAlerts) then ShowServerAlert("Couldn't connect to " & appName & " on " & ¬ gasOurServer & " in zone " & gasOurZone & return & return & ¬ "The server may be down or the app may not allow remote events." & return & return & "Error was: " & err) else beep end if end ShowConnectAlert on ShowServerAlert(msg) set choice to ¬ display dialog msg buttons {"Reenter Password", "OK"} ¬ default button 2 with icon stop if (button returned of choice is not "OK") then GetFriend(true) end ShowServerAlert on ShowInitAlert() if ShowChoices("This script must first be activated by dropping exactly one item on it." & ¬ return & return & "Please see the information file that accompanied it.", ¬ {"Activate", "OK"}) is not "OK" then ¬ ChooseScriptAlias() end ShowInitAlert on ShowAlert(msgStr) if (kasAllowAlerts) then ¬ display dialog msgStr buttons {"Damn!"} ¬ default button 1 with icon stop end ShowAlert on ShowChoice(msgStr) return ShowChoices(msgStr, {"No", "Yes"}) is "Yes" end ShowChoice on ShowChoices(msgStr, choices) set choice to ¬ display dialog msgStr buttons choices ¬ default button (number of items of choices) ¬ with icon stop return (button returned of choice) end ShowChoices property kasKeyChainPassword : "PowerScript" -- Encrypt stored data with this property kasPrefsFileName : "PowerScript Prefs" -- File name in <Preferences> on KeyChainLookUp(zoneName, serverName, isLinking) set prefType to "πSRV" if (isLinking) then set prefType to "πLNK" try set myKeyData to load preference of type prefType ¬ named (zoneName & ":" & serverName) ¬ in file named kasPrefsFileName on error return {} end try return (encrypt the data myKeyData ¬ with password kasKeyChainPassword) end KeyChainLookUp on KeyChainSave(zoneName, serverName, isLinking, usr, pwd, ntPwd) set myKey to encrypt the data {usr, pwd, ntPwd} ¬ with password kasKeyChainPassword set prefType to "πSRV" if (isLinking) then set prefType to "πLNK" save preference myKey of type prefType ¬ named (zoneName & ":" & serverName) ¬ in file named kasPrefsFileName end KeyChainSave